package com.origin.app;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.databinding.BindingAdapter;

public class VerticalTextView extends RelativeLayout {
    public VerticalTextView(Context context) {
        this(context,null);
    }

    public VerticalTextView(Context context, AttributeSet attrs) {
        this(context,attrs,-1);
    }

    public VerticalTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context,attrs,-1,-1);
    }

    public VerticalTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(attrs);
    }

    String labelStr;
    String infoStr;
    TextView tvLabel;
    TextView tvInfo;
    int  tvColor;
    private void init(AttributeSet attrs) {
        View inflate = inflate(getContext(), R.layout.layout_vertical_text, this);
        TypedArray ta=getContext().obtainStyledAttributes(attrs,R.styleable.VerticalTextView);
        labelStr=ta.getString(R.styleable.VerticalTextView_tv_label);
        infoStr=ta.getString(R.styleable.VerticalTextView_tv_info);
        tvColor=ta.getColor(R.styleable.VerticalTextView_tv_color, ContextCompat.getColor(getContext(), R.color.black));
        ta.recycle();

        tvLabel=findViewById(R.id.tv_label);
        tvInfo=findViewById(R.id.tv_info);
        tvLabel.setText(labelStr);
        tvInfo.setText(infoStr);
        tvLabel.setTextColor(tvColor);
        tvInfo.setTextColor(tvColor);
    }

    @BindingAdapter("app:tv_label")
    public  static  void setLabel(VerticalTextView verticalTextView,String labelStr){
        verticalTextView.tvLabel.setText(labelStr);
    }
    @BindingAdapter("app:tv_label")
    public  static  void setLabel(VerticalTextView verticalTextView,int labelStr){
        verticalTextView.tvLabel.setText(String.valueOf(labelStr));
    }

    @BindingAdapter("app:select_bg")
    public  static  void selectBg(VerticalTextView verticalTextView,boolean select){
        if(select){
            verticalTextView.setBackgroundColor( Color.parseColor("#20000000"));
        }else{
            verticalTextView.setBackgroundColor(-1);
        }

    }

}
